#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QThread>
#include <QSettings>
#include "link/ModBusTcpWorker.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class QPushButton;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
signals:
    void sig_SetProNameDevType(QString proName,int DevType);
    void sig_SetIPPort(QString address,short port);
    void sig_SetReadStartAddressAndRegisterCount(QList<int> startAddress, QList<int> registerCount,int RegisterType);
    void sig_SetWriteStartAddressAndRegisterCount(int startAddress, int registerCount,QList<quint16> data);
    void sig_StartLoopReadRegister(bool start);

    void sig_AddWriteQueue(WriteData* data);   //增加写消息队列的数据

public slots:
    void  slot_readBoolData(int MsgId,QList<bool> data);  //发送解析后bool数据
    void  slot_readfloatData(int MsgId,QList<float> data);  //发送解析后bool数据
    void slot_ConnectionState(bool isConnectionState);

    void slot_WriteDataQueueFinish();//写队列完成


private slots:

    void on_btn_Link_clicked();

    void on_comboBox_currentIndexChanged(int index);

    void on_btn_ARun_clicked();

    void on_btn_FRotation_1_clicked();

    void on_btn_RRotation_1_clicked();

    void on_btn_FRotation_2_clicked();

    void on_btn_RRotation_2_clicked();

    void on_btn_FRotation_3_clicked();

    void on_btn_RRotation_3_clicked();

    void on_btn_MRun_1_clicked();

    void on_btn_MRun_2_clicked();

    void on_btn_MRun_3_clicked();

    void on_btn_SFRotation_1_clicked();

    void on_btn_SRRotation_1_clicked();

    void on_btn_SFRotation_2_clicked();

    void on_btn_SRRotation_2_clicked();

    void on_btn_SFRotation_3_clicked();

    void on_btn_SRRotation_3_clicked();

    void on_dSBox_ATargetValue_valueChanged(double arg1);

    void on_dSBox_MTargetValue_1_valueChanged(double arg1);


    void on_dSBox_MTargetValue_2_valueChanged(double arg1);

    void on_dSBox_MTargetValue_3_valueChanged(double arg1);

    void on_spBox_StepValue_1_valueChanged(int arg1);

    void on_spBox_StepValue_2_valueChanged(int arg1);

    void on_spBox_StepValue_3_valueChanged(int arg1);

    void on_btn_Write_clicked();

    void on_btn_SetStep_1_clicked();

    void on_btn_SetStep_2_clicked();

    void on_btn_SetStep_3_clicked();

private:
    Ui::MainWindow *ui;
    //样式
    void loadStyle(QString currentStyle = "black");

    QSettings* m_Settings;
    QString  m_Style;

    QThread* m_Thread;
    ModBusTcpWorker* m_ModBusTcpWorker;

    QList<bool> m_SwtichStatusPre;      //所有开关状态
    bool m_SwtichStatusModePre_1;       //模式一的开关状态记录，就是运行按钮(解析的时候根据各个模式各存各的上一个数据)
    QList<bool> m_SwtichStatusModePre_2;//模式二的开关状态记录            (解析的时候根据各个模式各存各的上一个数据)


    QList<bool> m_LimitStatusPre; //限位状态记录

    QList<bool> m_StepStatusPre; //步进状态记录

    bool bConnectionState;        //是否在线的状态

    const QString BtnRunGray =
        "QPushButton"
        "{"
        "background-color: rgba(255,255,255,0.2);"
        "border: none;"
        "border-radius: 15px;"
        "color: white;"
        "padding: 4px 12px;"
        "font-size: 12pt;"
        "font-family: 'Microsoft YaHei';"
        "font-weight: bold;"
        "}"
        "QPushButton:hover"
        "{"
        "background-color: rgba(255,255,255,0.1);"
        "}"
        "QPushButton::pressed"
        "{"
        "background-color: rgba(255,255,255,0.1);"
        "color: #007fff;"
        "}"
        ;

    const QString BtnRunBlue =
        "QPushButton"
        "{"
        "background-color: rgba(255,255,255,0.2);"
        "border: none;"
        "border-radius: 15px;"
        "color: white;"
        "padding: 4px 12px;"
        "font-size: 12pt;"
        "font-family: 'Microsoft YaHei';"
        "font-weight: bold;"
        "}"
        "QPushButton:hover"
        "{"
        "background-color: rgba(255,255,255,0.05);"
        "}"
        "QPushButton::pressed"
        "{"
        "background-color: rgba(255,255,255,0.05);"
        "color: #007fff;"
        "}"
        "QPushButton:disabled { "
        "color: rgba(180,180,180,0.7);"
        "}"


            ;

    const QString BtnRunBlueGreen =
        "QPushButton"
        "{"
        "background-color: rgba(255,255,255,0.2);"
        "border: none;"
        "border-radius: 15px;"
        "color: #00ff24;"
        "padding: 4px 12px;"
        "font-size: 12pt;"
        "font-family: 'Microsoft YaHei';"
        "font-weight: bold;"
        "}"
        "QPushButton:hover"
        "{"
        "background-color: rgba(255,255,255,0.1);"
        "}"
        "QPushButton::pressed"
        "{"
        "background-color: rgba(255,255,255,0.1);"
        "}"
            ;

    const QString BtnRunGreen =
            "QPushButton"
            "{"
            "background-color: #0fc43e;"
            "border: none;"
            "border-radius: 2px;"
            "color: white;"
            "padding: 4px 11px;"
            "font-size: 11pt;"
            "}"
            "QPushButton:hover"
            "{"
            "background-color: #0dda42;"
            "}"
            "QPushButton::pressed"
            "{"
            "background-color: #0fc43e;"
            "}"
            "QPushButton:disabled"
            "{"
            "background-color: #43bd63;"
            "color: rgb(78,78,78);"
            "}"
            ;



    QList<QWidget*> m_WidgetModes;

    quint8 m_CurrentMode;//当前模式

    QList <QList<QPushButton* > > m_AllBtns;//各个模式的按钮 里面的list[0] 对应模式1的按钮 list[1] 对应模式2的按钮 list[2]对应模式3的按钮
    QList<QPushButton* >  m_AllStateBtns;//所有的状态按钮

};
#endif // MAINWINDOW_H
